package org.apache.http.examples.client;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

/**
 * 
 */
public class ClientExecuteProxy {

	public static void main(String[] args) throws Exception {

		HttpHost proxy = new HttpHost("http.internetpsa.inetpsa.com", 80, "http");

		DefaultHttpClient httpclient = new DefaultHttpClient();

		try {

			httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
			
			httpclient.getCredentialsProvider().setCredentials(new AuthScope("http.internetpsa.inetpsa.com", new Integer(80)),
					new UsernamePasswordCredentials("u336654", "intro793"));

			// https://secure.ogone.com/ncol/test/querydirect.asp
			HttpHost target = new HttpHost("svn2.informatique.inetpsa.com", 80, "http"); // ("issues.apache.org", 443, "https");
			HttpGet req = new HttpGet("/svn/ciq00/Etudes/trunk/");

			HttpResponse rsp = httpclient.execute(target, req);

			HttpEntity entity = rsp.getEntity();

			System.out.println(rsp.getStatusLine());

			Header[] headers = rsp.getAllHeaders();
			for (int i = 0; i < headers.length; i++) {

				System.out.println(headers[i]);
			}

			if (entity != null) {

				System.out.println(EntityUtils.toString(entity));
			}

		} finally {
			httpclient.getConnectionManager().shutdown();
		}
	}

}